/*
 * Delete.java
 *
 * Created on 15 marzec 2007, 23:20
 *
 */

package arocms.gallery;

import arocms.business.ImageDAO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author arek
 */
public class Delete extends Action{

    private static final String FAILURE = "failure";
    private static final String SUCCESS = "success";
    private Logger log = Logger.getLogger(this.getClass());
    
    /** Creates a new instance of Delete */
    public Delete() {
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        log.debug("--> execute");
        try {
            String id = request.getParameter("id");
            Long pk = new Long(id);
            boolean status = new ImageDAO().delete(pk);
            if (status==false) return mapping.findForward(FAILURE);
        } catch (Exception ex) {
            return mapping.findForward(FAILURE);
        }
        log.debug("<-- execute");
        return mapping.findForward(SUCCESS);
    }
    
}
